package com.example.food_contract_system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.food_contract_system.domain.Type;
import com.example.food_contract_system.service.TypeService;
import com.example.food_contract_system.mapper.TypeMapper;
import com.example.food_contract_system.util.R;
import com.example.food_contract_system.vo.SelectByKeyVo;
import com.example.food_contract_system.vo.TypeFilterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author Lhy
* @description 针对表【type】的数据库操作Service实现
* @createDate 2023-07-08 20:16:02
*/
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService{

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public R getType() {
        List<Type> typeList = typeMapper.selectList(null);

        if (typeList.size() > 0){
            List<TypeFilterVo> typeFilterVos = typeList.stream().map(type -> {
                TypeFilterVo typeFilterVo = new TypeFilterVo();

                typeFilterVo.setValue(String.valueOf(type.getTId()));
                typeFilterVo.setText(type.getTName());

                return typeFilterVo;
            }).collect(Collectors.toList());

            return R.ok().put("data",typeFilterVos);
        }
        return R.error();
    }
}




